package com.dony.web.controller.shop;

import com.dony.common.core.controller.BaseController;
import com.dony.common.core.domain.AjaxResult;
import com.dony.common.core.page.TableDataInfo;
import com.dony.shop.domain.GlobalProduct;
import com.dony.shop.domain.Item;
import com.dony.shop.domain.ItemModel;
import com.dony.shop.domain.vo.PriceVo;
import com.dony.shop.domain.vo.ProductVo;
import com.dony.shop.service.IGlobalProductService;
import com.dony.shop.service.IPriceConfigService;
import com.dony.shop.service.IProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@Slf4j
@RestController
@RequestMapping("/shopee/price")
public class ChangePriceController extends BaseController {


    @Resource
    IProductService productService;
    @Resource
    IGlobalProductService globalProductService;
    @Resource
    IPriceConfigService priceConfigService;


    /**
     * 全球商品查询
     *
     * @param productVo
     * @return
     */
    @RequestMapping("/product/list")
    public TableDataInfo list(ProductVo productVo) {
        startPage();
        List<GlobalProduct> pros = productService.listByParam(productVo);
        TableDataInfo dataTable = getDataTable(pros);
        //封装order数据
        List<ProductVo> productVos = productService.handleProdcutList(pros);
        dataTable.setRows(productVos);
        return dataTable;
    }

    /**
     * 修改价格
     */
    @PostMapping("/change")
    public AjaxResult changePrice(@RequestBody List<ProductVo> products) {
        productService.changePrice(products);
        return AjaxResult.success();
    }

    /**
     * 修改单个的价格
     */
    @PostMapping("/change/single")
    public AjaxResult changeSinglePrice(@RequestBody Item item) {
        return AjaxResult.success(productService.changeSinglePrice(item));
    }


    /**
     * 单个计算价格
     *
     * @param
     * @return
     */
    @RequestMapping("/single/compute")
    public AjaxResult getComputedPrice(@RequestBody ItemModel model) {
        return AjaxResult.success(priceConfigService.getComputedPrice(model));
    }

    /**
     * 根据重量和价格计算其他站点价格
     *
     * @param
     * @return
     */
    @RequestMapping("/compute")
    public AjaxResult getLinePriceDetail(@RequestBody PriceVo priceVo) {
        return AjaxResult.success(productService.getComputePrice(priceVo));
    }



}
